package com.example.myapplication.data;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import java.util.List;

@Dao
public interface RecordDao {
    @Insert
    void insert(Record record);

    @Insert
    long insertAndGetId(Record record);

    @Update
    void update(Record record);

    @Delete
    void delete(Record record);

    @Query("DELETE FROM records WHERE id = :recordId")
    void deleteById(int recordId);

    @Query("SELECT * FROM records ORDER BY date DESC")
    LiveData<List<Record>> getAllRecords();

    @Query("SELECT * FROM records WHERE date >= :startDate AND date <= :endDate ORDER BY date DESC")
    LiveData<List<Record>> getRecordsByDateRange(long startDate, long endDate);

    @Query("SELECT * FROM records")
    List<Record> getAllRecordsDirectly();

    @Query("SELECT SUM(amount) FROM records WHERE isExpense = 1 AND date >= :startDate AND date <= :endDate")
    LiveData<Double> getTotalExpenseByDateRange(long startDate, long endDate);

    @Query("SELECT SUM(amount) FROM records WHERE isExpense = 0 AND date >= :startDate AND date <= :endDate")
    LiveData<Double> getTotalIncomeByDateRange(long startDate, long endDate);

    @Query("DELETE FROM records")
    void deleteAllRecords();
} 